package com.aaa.pro.service;

import com.aaa.pro.dao.ProAppraiseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Classname ProAppraiseServiceImpl
 * @Description TODO
 * @Date 2020/1/12 15:55
 * @Created by admin
 * @author:GT
 * @version:1.0.0
 */
@Service
public class ProAppraiseServiceImpl implements ProAppraiseService {

    @Autowired
    private ProAppraiseDao proAppraiseDao;

    @Override
    public List<Map> getProAppraise() {
        return proAppraiseDao.getProAppraise();
    }

    @Override
    public List<Map> getHomeComment() {
        List<Map> list = proAppraiseDao.getHomeComment();
        for (int i = 0 ; i < list.size() ; i++){
            String[] strList = list.get(i).get("pics").toString().split(",");
            list.get(i).put("pics",strList);
        }
        return list;
    }

    @Override
    public Map getCommentData() {
        Map map = new HashMap();
        if (proAppraiseDao.getCommentData().size() > 0){
            long number = (long)proAppraiseDao.getCommentData().get(0).get("evaluationNumber");
            String numbers;
            if (number > 1000){
                numbers = "999+";
            }else {
                numbers = number + "条";
            }
            map.put("evaluationNumber", numbers);
            map.put("avgScore", proAppraiseDao.getCommentData().get(0).get("avgScore"));
            return map;
        }
        return null;
    }


    @Override
    public List<Map> getAllevaluation(int sequenceNum) {
        int num = (sequenceNum-1)*5;
        List<Map> list = proAppraiseDao.getAllevaluation(num);
        for (int i = 0 ; i < list.size() ; i++){
            String[] strList = list.get(i).get("pics").toString().split(",");
            list.get(i).put("pics",strList);
        }
        return list;
    }

    @Override
    public int AddComment(Map map) {
        return proAppraiseDao.AddComment(map);
    }
}
